import time
import pymysql

'''
-- test.`user` definition

CREATE TABLE `user` (
  `id` int NOT NULL AUTO_INCREMENT,
  `name` varchar(100) DEFAULT NULL,
  `sex` int DEFAULT NULL,
  UNIQUE KEY `user_un` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1840231 DEFAULT CHARSET=utf8;
'''

db=pymysql.connect(host='localhost',user='root',password='123456',port=3306,db='test')
cur=db.cursor() ##获取游标

sql = 'insert user(name,sex) values (%s,1)'
# cur.execute(sql)
namel = ['张三']*1000000

starttime = time.time()
#批处理
cur.executemany(sql,namel)
endtime = time.time()

#10万条11s，正常时间
print(endtime-starttime)
#事务提交
db.commit()